﻿using System;
using System.Windows.Input;
using System.Windows.Media;
using Might.GraphicsEditor.GraphicsObjects;
using Might.GraphicsEditor.Presenter;
using Might.Modelica.Annotations.Graphics;

namespace Might.GraphicsEditor.Tools {
    /// <summary>
    /// Class used for adding new Ellipse canvas
    /// </summary>
    internal class EllipseTool : ITool {
        /// <summary>
        /// Constructor for Rubberband class
        /// </summary>
        /// <param name="gl">Main Drawing canvas</param>
        internal EllipseTool(IconPresenter gl) {
            graphics = gl;
        }

        /// <summary>
        /// Througput function for receiving mouse down events from canvas.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal override void GetMouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
            var ge = new GraphicsEllipse();
            if (ge == null) {
                throw new NullReferenceException("calling CreatePrimitive returned null");
            }

            graphics.ga.AddPrimitive(ge);
            ge.Width = ge.Height = 1;
            ge.Left = e.GetPosition(graphics.canvas).X - 1;
            ge.Top = e.GetPosition(graphics.canvas).Y - 1;
            ge.Fill = new SolidColorBrush(Colors.Green);
            ge.Stroke = new SolidColorBrush(Colors.Black);

            GraphicsComponent gc = new LeafEllipse(ge);

            graphics.canvas.Children.Add(gc);
            graphics.SetShape(gc);
            // TODO simplify or rewrite this
            IconEditor.SelectedCanvas.resizer.Resizer_MouseLeftButtonDown(IconEditor.SelectedCanvas.resizer.BR, e);

            e.Handled = true;
        }

        /// <summary>
        /// Througput function for receiving mouse move events from canvas.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal override void GetMouseMove(object sender, MouseEventArgs e) {}

        /// <summary>
        /// Througput function for receiving mouse up events from canvas.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal override void GetMouseLeftButtonUp(object sender, MouseButtonEventArgs e) {}
    }
}
